package com.test.sshshiro.entity;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.test.sshshiro.framework.BaseUpdatableEntity;

@Entity
@Table(name="acct_authority")
public class AcctAuthority extends BaseUpdatableEntity {

	private String authId;
	private String authName;
	public String getAuthId() {
		return authId;
	}
	public void setAuthId(String authId) {
		this.authId = authId;
	}
	public String getAuthName() {
		return authName;
	}
	public void setAuthName(String authName) {
		this.authName = authName;
	}
	
	@ManyToOne
	@Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE })
	@JoinColumn(name = "parent_id", nullable = true)
	@JsonIgnore
	private  AcctAuthority parent;
	public AcctAuthority getParent() {
		return parent;
	}
	public void setParent(AcctAuthority parent) {
		this.parent = parent;
	}
	
	
	@OneToMany(mappedBy = "parent", cascade = { javax.persistence.CascadeType.ALL }, fetch = FetchType.LAZY)
	@JsonIgnore
	private List<AcctAuthority> children = new ArrayList<AcctAuthority>();
	public List<AcctAuthority> getChildren() {
		return children;
	}
	public void setChildren(List<AcctAuthority> children) {
		this.children = children;
	}
	
	@JsonIgnore
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "acct_role_authority", joinColumns = { @JoinColumn(name = "AUTHORITY_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") })
	private Set<AcctRole> roleList = new HashSet<AcctRole>();

	public Set<AcctRole> getRoleList() {
		return roleList;
	}

	public void setRoleList(Set<AcctRole> roleList) {
		this.roleList = roleList;
	}
	
	
	
}
